Xbasic

Array initialize Method

Syntax

V <array>.initialize(C data[,L append])

Arguments

dataCharacter

The values to use to initialize the array elements.

appendLogical

Default value is false. If true, data will be appended to the array. Otherwise, existing data in the array will be deleted.

Description

Initialize the array from a string of newline separated entries.

Discussion

The <array>.initialize() method populates an array with values contained in a CR-LF delimited character list.

For example, assume that the string mydata contains this:

dim mydata as C
mydata =<<%str%
blue
green
red
purple
%str%

The following commands will dimension a new array and initialize the first four array elements:

dim colors[10] as C
colors.initialize(mydata)

? colors
= [1] = "blue"
[2] = "green"
[3] = "red"
[4] = "purple"
[5] = ""
[6] = ""
[7] = ""
[8] = ""
[9] = ""
[10] = ""

Example

The following script populates an array with the names of the tables in the current database. The A5.TABLE_ENUM() method returns a CR-LF delimited list of all of the tables in a database when called with no argument.

dim tablelist[100] as C
tablelist.initialize(:a5.table_enum())

This script creates and populates an array with 5 elements. The <<%list% ... %list% construct is used to indicate to Xbasic that you are entering character data that spans more than one physical line.

dim colors[5] as C
colors.initialize(<<%list%
blue
red
green
yellow
pink
%list%)

The following script populates an array with the first and last names of people in Massachusetts from the Customer table.

dim names[100] as C
list = table.external_record_content_GET("customer", "alltrim(firstname) + ' ' + lastname", "lastname", "state = 'ma'")
names.initialize(list)

See Also